
/**
 * Write a description of class StatisticsDisplay here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class StatisticsDisplay implements Observer, DisplayElement
{
    private float max_temperature;
    private float min_temperature = 200;
    private float sum_temperatures;
    private int num_readings;
    private Subject weatherData;
    
    public StatisticsDisplay(Subject weatherData){
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }
    
    public void update(float temperature, float humidity, float pressure){
        sum_temperatures += temperature;
        
        if(temperature > max_temperature)
            max_temperature = temperature;
        if(temperature < min_temperature)
            min_temperature = temperature;
        
        num_readings++;
        
        display();
    }
    
    public void display(){
        System.out.println("Min/Max/Avg temperature: " + min_temperature + "F / " + max_temperature +
            "F / " + (sum_temperatures/num_readings) + "F");
    }
}